<?php
class News_model extends Model
{
	//-------------------------------------------------NEWS-----------------------------------------------
	function News_model()
	{
		parent::Model();
	}
	function get_all_news($num,$offset)
	{
		$query = $this->db->get('xn_news',$num,$offset);
		return $query->result();
	}
	function get_news()
	{
		$id = $this->uri->segment(3);
		$this->db->where('id_news',$id);
		$query = $this->db->get('xn_news');
		return $query->row();
	}
	function get_news_id($id)
	{
		
	}
	function get_news_arr($field,$val)
	{
		$this->db->where($field,$val);
		$this->db->join('xn_news_category nc','n.id_news_category = nc.id_news_category');
		$query = $this->db->get('xn_news n');
		return $query->row();
	}
	function get_num_news()
	{
		$query = $this->db->get('xn_news');
		return $query->num_rows();
	}
	function save_news($data)
	{
		$id = $this->uri->segment(3);
		if($id != 0)
		{
			$this->db->where('id_news',$id);
			return $this->db->update('xn_news',$data);
		}
		else
		{
			return $this->db->insert('xn_news',$data);
		}
	}
	function del_news($id)
	{
		$this->db->where('id_news',$id);
		return $this->db->delete('xn_news');
	}
	//-------------------------------------------------CATEGORY---------------------------------------------
	function get_all_news_cat()
	{
		$query = $this->db->get('xn_news_category');
		return $query->result();
	}
	function get_all_news_category($num,$offset)
	{
		$query = $this->db->get('xn_news_category',$num,$offset);
		return $query->result();
	}
	function get_news_category_by_parent($id_parent)
	{
		$this->db->where('id_parent',$id_parent);
		$query = $this->db->get('xn_news_category');
		return $query->result();
	}
	function get_news_category()
	{
		$id = $this->uri->segment(3);
		$this->db->where('id_news_category',$id);
		$query = $this->db->get('xn_news_category');
		return $query->row();
	}
	function get_num_news_category()
	{
		$query = $this->db->get('xn_news_category');
		return $query->num_rows();
	}
	function save_news_category($data)
	{
		$id = $this->uri->segment(3);
		if($id != 0)
		{
			$this->db->where('id_news_category',$id);
			return $this->db->update('xn_news_category',$data);
		}
		else
		{
			return $this->db->insert('xn_news_category',$data);
		}
	}
	function del_news_category($id)
	{
		$this->db->where('id_news_category',$id);
		return $this->db->delete('xn_news_category');
	}
}
?>